<?php
class region{
	public function __construct(){
		
	}

	//所有区域
	public function allRegion(){
		$sql = 'SELECT * FROM '.DB_PREFIX.'region';
		$result = $GLOBALS['db']->getall($sql);
		return $result;
	}
	
	//更具en查找对应的区域
	public function regionEnSearch($en){
		$result = NULL;
		if($en){
			$en = addslashes($en);
			$sql = 'SELECT * FROM '.DB_PREFIX."region WHERE `en`='{$en}'";
			$result = $GLOBALS['db']->fetch_first($sql);
			if(!$result){
				require CHENCY_ROOT.'./source/conf/city.php';
				$firstEn  = strtoupper($en[0]);
				// echo $firstEn;
				$key_a = array();
				$key_b = array();
				$key_c = array();
				$key_d = array();
				$key_e = array();
				$key_f = array();
				if(is_array($city['list'][$firstEn]) && !empty($city['list'][$firstEn]))
				{
					foreach ($city['list'][$firstEn] as $key => $val) 
					{
						$key_a[] = $key;
					}
				}
				foreach ($city['hot']['YL'] as $keya => $vala) {
					$key_b[] = $keya;
				}
				foreach ($city['hot']['EL'] as $keyb => $valb) {
					$key_c[] = $keyb;
				}
				foreach ($city['hot']['SL'] as $keyd => $vald) {
					$key_d[] = $keyd;
				}
				foreach ($city['hot']['ML'] as $keye => $vale) {
					$key_e[] = $keye;
				}
				foreach ($city['hot']['WL'] as $keyf => $valf) {
					$key_f[] = $keyf;
				}
				// print_r($key_b);
				if(in_array($en,$key_a))
				{
					$cityAll = $city['list'][$firstEn];
					if(isset($cityAll[$en])){
						if($cityAll[$en])
						{
							$result['name'] = $cityAll[$en];
							$result['en']   = $en;
						} 
					}
				}elseif (in_array($en,$key_b)) 
				{
					$cityAB = $city['hot']['YL'];
					if(isset($cityAB[$en])){
						if($cityAB[$en])
						{
							$result['name'] = $cityAB[$en];
							$result['en']   = $en;
						}
					}
				}elseif (in_array($en,$key_c)) 
				{
					$cityAC = $city['hot']['EL'];
					if(isset($cityAC[$en])){
						if($cityAC[$en])
						{
							$result['name'] = $cityAC[$en];
							$result['en']   = $en;
						} 
					}
				}elseif (in_array($en,$key_d)) 
				{
					$cityAD = $city['hot']['SL'];
					if(isset($cityAD[$en])){
						if($cityAD[$en])
						{
							$result['name'] = $cityAD[$en];
							$result['en']   = $en;
						} 
					}
				}elseif (in_array($en,$key_e)) 
				{
					$cityAE = $city['hot']['ML'];
					if(isset($cityAE[$en])){
						if($cityAE[$en])
						{
							$result['name'] = $cityAE[$en];
							$result['en']   = $en;
						} 
					}
				}elseif (in_array($en,$key_f)) 
				{
					$cityAF = $city['hot']['WL'];
					if(isset($cityAF[$en])){
						if($cityAF[$en])
						{
							$result['name'] = $cityAF[$en];
							$result['en']   = $en;
						} 
					}
				}
			}
		}
		return $result;
	}
}